package com.fix.model;

import java.io.UnsupportedEncodingException;

import com.fix.util.FixClientController;
import com.google.gson.Gson;

public class Line {
	private String text_raw;
	private String bullet;
    private int level;
    private int lineid;
    private String text_rendered;
    
    private String textTranslated;
    
	public String getText_raw() {
		return text_raw;
	}
	public void setText_raw(String text_raw) {
		this.text_raw = text_raw;
	}
	public String getBullet() {
		return bullet;
	}
	public void setBullet(String bullet) {
		this.bullet = bullet;
	}
	public int getLevel() {
		return level;
	}
	public void setLevel(int level) {
		this.level = level;
	}
	public int getLineid() {
		return lineid;
	}
	public void setLineid(int lineid) {
		this.lineid = lineid;
	}
	public String getText_rendered() {
		return text_rendered;
	}
	public void setText_rendered(String text_rendered) {
		this.text_rendered = text_rendered;
	}
	
	public String getTextTranslated() {
		final FixClientController fixClientController = new FixClientController();
		Gson gson = new Gson();
		String jsonfromyadex;
		try {
			jsonfromyadex = fixClientController.translate(text_raw);
			if("Invalid query".equalsIgnoreCase(jsonfromyadex)) {
				return "Invalid query: " + text_raw;
			}
			Translated tr = gson.fromJson(jsonfromyadex, Translated.class);
			final String[] ls = tr.getText();
			String s = "";
			for (int i = 0; i < ls.length; i++) {
				 s += ls[i];
			}	
			this.textTranslated = s;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		return textTranslated;
	}
	public void setTextTranslated(String textTranslated) {
		this.textTranslated = textTranslated;
	}
}
